﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HWmanagementClient.HWManager;

namespace HWmanagementClient.Models
{

    public class HomeworkClientModel
    {
        public int id { get; set; }
        public int courseid { get; set; }
        public string userid { get; set; }
        public int fileid { get; set; }
        public string title { get; set; }
        public string shortdesc { get; set; }
        public DateTime deadline { get; set; }

        public string deadline2 { get { return string.Format("{0}. {1}. {2}. - {3}:{4}:{5}",deadline.Year,
            deadline.Month,deadline.Day,deadline.Hour,deadline.Minute,deadline.Second); } }
        public bool isupload { get { return deadline > DateTime.Now; } }

        private string dl3;
        public string deadline3
        {
            get
            {
                return dl3;
            }
            set
            {
                dl3 = value;
                var date = value.Split(new[] { '/' });
                deadline = new DateTime(int.Parse(date[2]), int.Parse(date[0]), int.Parse(date[1]));
            }
        }

        public string filename
        {
            get
            {
                try
                {
                    ManagerClient proxy = new ManagerClient();

                    return proxy.getFileName(fileid).Split(new[] { '\\' }).Last();
                }
                catch
                {
                    return "nincs fájl";
                }
            }
          }

        public string fileurl
        {
            get
            {
                try
                {
                    ManagerClient proxy = new ManagerClient();

                    return proxy.getFileName(fileid);
                }
                catch
                {
                    return "#";
                }
            }
            
        }

        public int groupid
        {
            get
            {
                ManagerClient proxy = new ManagerClient();
                try
                {
                    return proxy.getGroupOnHw(id);
                }
                catch 
                {
                    return -1;
                }
            }
        }


        public static HomeworkClientModel fromWCFmodel(HomeworkModel mo)
        {
            return new HomeworkClientModel()
            {
                courseid = mo.courseid,
                deadline = mo.deadline,
                fileid = mo.fileid,
                id = mo.id,
                shortdesc = mo.shortdesc,
                title = mo.title,
                userid = mo.userid
            };
        }
    }

    public class GradeModel : HomeworkClientModel
    {
        public int grade { get; set; }
        public string comment { get; set; }

        public static GradeModel fromBase(HomeworkClientModel mo)
        {
            return new GradeModel()
            {
                courseid = mo.courseid,
                deadline = mo.deadline,
                fileid = mo.fileid,
                id = mo.id,
                shortdesc = mo.shortdesc,
                title = mo.title,
                userid = mo.userid
            };
        }
    }
    
    public class StudentHomeworks
    {
        public List<HomeworkClientModel> Homeworks { get; set; }
        public List<SubjectClientModel> Subjects { get; set; }
        public List<GradeModel> Grades { get; set; }

    }
}